package org.example.controller;

import lombok.extern.slf4j.Slf4j;
import org.example.pojo.Dept;
import org.example.pojo.Emp;
import org.example.pojo.Query;
import org.example.pojo.Result;
import org.example.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;
@Slf4j
@RestController
@RequestMapping("/emps")
public class EmpController {
    @Autowired
    private EmpService empService;

    @GetMapping
    public Result list(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pageSize, String keyword, Integer gender, @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginTime, @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endTime) {
        log.info("分页查询员工列表");

        // 调用Service查询部门列表

        Query empList = empService.list(page, pageSize, keyword, gender, beginTime, endTime);


        return Result.success(empList);
    }

    @DeleteMapping("/{ids}")
    public Result deleteEmps(@PathVariable List<Integer> ids) {
        log.info("批量删除员工，id：{}", ids);

        empService.delete(ids);

        return Result.success();
    }

    @PostMapping("/insert")
    public Result insert(@RequestBody Emp emp) {
        log.info("新增员工，员工信息：{}", emp);

        empService.insert(emp);

        return Result.success();
    }
}
